package com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.repository.HddcWyGeomorphysvypointNativeRepository;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.repository.HddcWyGeomorphysvypointRepository;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.repository.entity.HddcWyGeomorphysvypointEntity;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.service.HddcWyGeomorphysvypointService;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.viewobjects.HddcWyGeomorphysvypointQueryParams;
import com.css.zfzx.sjcj.modules.hddcwyGeomorphySvyPoint.viewobjects.HddcWyGeomorphysvypointVO;
import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.sys.dict.repository.entity.DictItemEntity;
import com.css.bpm.platform.utils.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lihelei
 * @date 2020-12-01
 */
@Service
public class HddcWyGeomorphysvypointServiceImpl implements HddcWyGeomorphysvypointService {

	@Autowired
    private HddcWyGeomorphysvypointRepository hddcWyGeomorphysvypointRepository;
    @Autowired
    private HddcWyGeomorphysvypointNativeRepository hddcWyGeomorphysvypointNativeRepository;

    @Override
    public JSONObject queryHddcWyGeomorphysvypoints(HddcWyGeomorphysvypointQueryParams queryParams , int curPage,
                                                    int pageSize) {
        Page<HddcWyGeomorphysvypointEntity> hddcWyGeomorphysvypointPage =
                this.hddcWyGeomorphysvypointNativeRepository.queryHddcWyGeomorphysvypoints(queryParams , curPage, pageSize);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(hddcWyGeomorphysvypointPage);
        return jsonObject;
    }


    @Override
    public HddcWyGeomorphysvypointEntity getHddcWyGeomorphysvypoint(String id) {
        HddcWyGeomorphysvypointEntity hddcWyGeomorphysvypoint = this.hddcWyGeomorphysvypointRepository.findById(id).orElse(null);
         return hddcWyGeomorphysvypoint;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public HddcWyGeomorphysvypointEntity saveHddcWyGeomorphysvypoint(HddcWyGeomorphysvypointEntity hddcWyGeomorphysvypoint) {
        String uuid = UUIDGenerator.getUUID();
        hddcWyGeomorphysvypoint.setId(uuid);
        hddcWyGeomorphysvypoint.setCreateUser(PlatformSessionUtils.getUserId());
        hddcWyGeomorphysvypoint.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        this.hddcWyGeomorphysvypointRepository.save(hddcWyGeomorphysvypoint);
        return hddcWyGeomorphysvypoint;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public HddcWyGeomorphysvypointEntity updateHddcWyGeomorphysvypoint(HddcWyGeomorphysvypointEntity hddcWyGeomorphysvypoint) {
        hddcWyGeomorphysvypoint.setUpdateUser(PlatformSessionUtils.getUserId());
        hddcWyGeomorphysvypoint.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        this.hddcWyGeomorphysvypointRepository.save(hddcWyGeomorphysvypoint);
        return hddcWyGeomorphysvypoint;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteHddcWyGeomorphysvypoints(List<String> ids) {
        List<HddcWyGeomorphysvypointEntity> hddcWyGeomorphysvypointList = this.hddcWyGeomorphysvypointRepository.findAllById(ids);
        if(!PlatformObjectUtils.isEmpty(hddcWyGeomorphysvypointList) && hddcWyGeomorphysvypointList.size() > 0) {
            for(HddcWyGeomorphysvypointEntity hddcWyGeomorphysvypoint : hddcWyGeomorphysvypointList) {
                this.hddcWyGeomorphysvypointRepository.delete(hddcWyGeomorphysvypoint);
            }
        }
    }

    @Override
    public List<DictItemEntity> getValidDictItemsByDictCode(String dictCode) {
        List<DictItemEntity> validDictItems = PlatformAPI.getDictAPI().getValidDictItemsByDictCode(dictCode);
        return validDictItems;
    }

    @Override
    public BigInteger queryHddcWyGeomorphysvypoint(HddcWyGeomorphysvypointQueryParams queryParams) {
        BigInteger bigInteger = hddcWyGeomorphysvypointNativeRepository.queryHddcWyGeomorphysvypoint(queryParams);
        return bigInteger;
    }

}
